package cn.hicard.util;

import cn.hicard.risk.entity.SysOperateLog;
import cn.hicard.risk.service.sys.SysLogService;

/** 系统日志 */
public class SysLogger {
	
	private static SysLogger logger;
	private SysLogService logService;

	private SysLogger(){}
	
	/** 取得日志实例 */
	public static SysLogger getLogger(){
		if(logger == null){
			logger = new SysLogger();
			logger.logService = SpringContext.getBean(SysLogService.class);
		}
		return logger;
	}

	/** 记录[读取]日志 */
	public void logR(String operator, String remark){
		log("R",operator, remark);
	}
	/** 记录[新增]日志 */
	public void logC(String operator, String remark){
		log("C",operator, remark);
	}
	/** 记录[更新]日志 */
	public void logU(String operator, String remark){
		log("U",operator, remark);
	}	
	/** 记录[删除]日志 */
	public void logD(String operator, String remark){
		log("D",operator, remark);
	}
	/** 记录日志 */
	public void log(String operateType, String operator, String remark){
		SysOperateLog log = new SysOperateLog();
		log.setOperateTime(DateHelp.dateTime());
		log.setOperateType(operateType);
		log.setOperator(operator);
		log.setRemark(remark);
		try {
			logService.save(log);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
